package com.sgb.goods.widget.pop;

import android.content.Context;
import android.util.Pair;
import android.view.View;

import com.sgb.goods.BR;
import com.sgb.goods.R;
import com.sgb.goods.databinding.GoodsPopShowVipPriceBinding;
import com.sgb.goods.utils.base.adapter.BaseCommonAdapter;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 只做展示数据的底部PopWindow
 */
public class ShowVipPriceDetailWindow extends BasePopWindow {

    private GoodsPopShowVipPriceBinding mDataBinding;
    public BaseCommonAdapter<Pair<String, String>> mAdapter;

    public ShowVipPriceDetailWindow(Context context ) {
        super(context, DIR_DOWN_UP);
    }

    @Override
    protected int popLayout() {
        mAdapter = new BaseCommonAdapter<>(R.layout.goods_pop_item_vip_price, BR.viewModel);
        return R.layout.goods_pop_show_vip_price;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        holder.setBinding(BR.svw, this);
        mDataBinding = (GoodsPopShowVipPriceBinding) holder.getmBinding();

        mDataBinding.okView.setOnClickListener(v -> {
            dissMiss();
            if (onResultClick != null) {
                onResultClick.result(null, null, null);
            }
        });
    }

    public void updateData(LinkedHashMap<String, String> map, String title, String rightTest) {
        mDataBinding.title.setText(title);
        mDataBinding.resetView.setVisibility(View.GONE);
        mDataBinding.okView.setText(rightTest);
        mDataBinding.okView.setVisibility(View.VISIBLE);

        List<Pair<String, String>> listData = new ArrayList<>();
        for (Map.Entry<String, String> entry : map.entrySet()) {
            listData.add(new Pair<>(entry.getKey(), entry.getValue()));
        }
        mAdapter.setNewData(listData);
    }

}
